import { _decorator, AnimationClip } from 'cc'
import { StateMachine } from '../../Base/StateMachine'
import { DIRECTION_ENUM, SHAKE_TYPE_ENUM } from '../../Enum'
import State, { ANIMATION_SPEED } from '../../Base/State'
import { DirectionSubStateMachine } from '../../Base/DirectionSubStateMachine'
const { ccclass, property } = _decorator

/**
 * Predefined variables
 * Name = AttackSubStateMachinePlayer
 * DateTime = Thu Jul 21 2022 15:36:38 GMT+0800 (中国标准时间)
 * Author = Zero_Y
 * FileBasename = AttackSubStateMachinePlayer.ts
 * FileBasenameNoExtension = AttackSubStateMachinePlayer
 * URL = db://assets/Scripts/Player/AttackSubStateMachinePlayer.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */

const BASE_URL = 'texture/player/attack'
@ccclass('AttackSubStateMachinePlayer')
export class AttackSubStateMachinePlayer extends DirectionSubStateMachine {
  constructor(fsm: StateMachine) {
    super(fsm)
    // 人物动画，转向
    this.stateMachines.set(
      DIRECTION_ENUM.TOP,
      new State(fsm, `${BASE_URL}/top`, AnimationClip.WrapMode.Normal, ANIMATION_SPEED, [
        {
          frame: ANIMATION_SPEED * 4, // 第 0.5 秒时触发事件
          func: 'onAttackShake', // 事件触发时调用的函数名称
          params: [SHAKE_TYPE_ENUM.TOP], // 向 `func` 传递的参数
        },
      ]),
    )
    this.stateMachines.set(
      DIRECTION_ENUM.BOTTOM,
      new State(fsm, `${BASE_URL}/bottom`, AnimationClip.WrapMode.Normal, ANIMATION_SPEED, [
        {
          frame: ANIMATION_SPEED * 4, // 第 0.5 秒时触发事件
          func: 'onAttackShake', // 事件触发时调用的函数名称
          params: [SHAKE_TYPE_ENUM.BOTTOM], // 向 `func` 传递的参数
        },
      ]),
    )
    this.stateMachines.set(
      DIRECTION_ENUM.LEFT,
      new State(fsm, `${BASE_URL}/left`, AnimationClip.WrapMode.Normal, ANIMATION_SPEED, [
        {
          frame: ANIMATION_SPEED * 4, // 第 0.5 秒时触发事件
          func: 'onAttackShake', // 事件触发时调用的函数名称
          params: [SHAKE_TYPE_ENUM.LEFT], // 向 `func` 传递的参数
        },
      ]),
    )
    this.stateMachines.set(
      DIRECTION_ENUM.RIGHT,
      new State(fsm, `${BASE_URL}/right`, AnimationClip.WrapMode.Normal, ANIMATION_SPEED, [
        {
          frame: ANIMATION_SPEED * 4, // 第 0.5 秒时触发事件
          func: 'onAttackShake', // 事件触发时调用的函数名称
          params: [SHAKE_TYPE_ENUM.RIGHT], // 向 `func` 传递的参数
        },
      ]),
    )
  }
}
